<template>
    <!-- 实现拦截是使用路由拦截 (没有进行登录的话会直接跳转到登录)-->
    <!-- 这个是个人中心页面  没有进行登录的话会直接跳转到登录 -->
    <div>
       <div class="top">
        <div class="user_text">
            <p>{{ username }}</p>
            <span> 吃货不是在干饭的路上就是在做饭，所以没有时间写签名</span>
        </div>
        <div>
            <img class="user_img" src="../assets/img/user_img.png" alt="">
        </div>
       </div>
        <div class="but">
            <div class="user_chang">
                <span>收藏菜谱</span>
                <span>0</span>
            </div>
            <div class="user_chang">
                <span>收藏笔记</span>
                <span>0</span>
            </div>
        </div>


        <button class="butt" @click="gotodenglu">退出登录</button>
    </div>
</template>
<script>

export default {
    data(){
        return{
            username : ""
        }
    },
    methods:{
        gotodenglu(){
            //退出登录，直接跳转到登录页面
            this.$router.push({path:'/denglu'})
        }
    },
    created(){
        //获取本地储存的数据
       let text =  localStorage.getItem("user")
        //将本地数据从JOSN格式转换成对象
       text = JSON.parse(text)
        console.log(text);
        // 将获取的数据中的用户名用变量接收
        this.username = text[0].username
       console.log(this.username);
       
    }
}
</script>
<style lang="less" scoped>
.butt{
    border-radius: 10px;
    margin: 20px 30px;
    border: 2px solid rgb(245, 209, 4);
    background-color: rgb(245, 209, 4);
    width: 80%;
}
.but{
    display: flex;
}
.user_chang{
    font-size: 20px;
    margin:  5px  10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}
.top{
    padding:0 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    img{
        width: 50px;
        height: 50px;
    }
    .user_text{
        p{
            margin: 10px 0;
            font-size: 30px;
        }
        span{
            margin: 5px 0;
            font-size: 20px;
        }
        display: flex;
        flex-direction: column;
    }
}

</style>